package com.lx.thread.MyThread.lx;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-04-23 00:44:48
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-04-23     张李鑫                     1.0         1.0 Version
 */
public class SycDemo {

    public static Object object=new Object();

    public static List list= Collections.synchronizedList(new ArrayList<>());

    public  void add() {
        synchronized (object) {
            try {
                Thread.sleep(1);
                System.out.println("add");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public  void get() {
        synchronized (object) {
            System.out.println(object.toString());
        }

        for (int i = 0; i < 10 ; i++) {

        }

        for (List h = list, p = h, q;;) {
        }
    }

    public static void main(String[] args) {
        for(int i=0; i<10; i++) {
            new Thread(()->{
                while(true) {
                    synchronized(object) {
                        System.out.println(Thread.currentThread().getName());
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }).start();
        }

        for(int i=0; i<10; i++) {
            new Thread(()->{
                while(true) {
                    System.out.println("no Synchronized");
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }

                }
            }).start();
        }
    }




}